package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark92Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark92 extends BaseMark {

    LayoutWatermark92Binding binding;

    public Mark92(@NonNull Context context) {
        super(context);
    }

    public Mark92(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark92(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark92Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            for (int i = 3; i < binding.mid.getChildCount(); i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark92Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.title, "title92", binding.titleLl);
        setText(binding.binding2, "time92", binding.binding1);
        setTime(binding.binding2, new SimpleDateFormat("yyyy/MM/dd"));
        setWeek(binding.binding3);
        setTime(binding.binding4, new SimpleDateFormat("HH:mm"));

        setText(binding.binding6, "weather92", binding.binding5);
        setText(binding.binding8, "person92", binding.binding7);
        setText(binding.binding10, "result92", binding.binding9);
        setText(binding.binding12, "unit92", binding.binding11);
        setText(binding.binding14, "didian92", binding.binding13);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title92", "标题"));
        list.add(new EditItem("time92", "时间"));
        list.add(new EditItem("weather92", "天气"));
        list.add(new EditItem("person92", "巡逻人"));
        list.add(new EditItem("result92", "巡逻结果"));
        list.add(new EditItem("unit92", "服务单位"));
        list.add(new EditItem("didian92", "地点"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding2, new SimpleDateFormat("yyyy/MM/dd"));
            setWeek(binding.binding3);
            setTime(binding.binding4, new SimpleDateFormat("HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }
}
